import { createRouter, createWebHistory } from 'vue-router'
import { Layout } from '@/layout/index.js'
// 默认不需要权限的页面
export const constantRouterMap = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/page/login/index.vue'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/page/errorPage/404.vue'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/page/errorPage/401.vue'),
    hidden: true
  },
  // { path: '/reg', name: 'register', component: () => import('@/page/register/index.vue'), hidden: true },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/page/redirect/index.vue')
    }]
  },
  {
    path: '/home',
    component: Layout,
    meta: {
      title: '首页',
      icon: 'House'
    },
    constant: true,
    alwaysShow: true,
    noDropdown: true,
    hidden: false,
    children: [{
      path: 'index',
      name: 'Index',
      meta: {
        title: '首页',
        icon: 'House',
        affix: true
      },
      component: () => import('@/page/home/index.vue')
    }]
  },
  {
    path: '/import',
    component: Layout,
    meta: {
      title: '导入模板',
    },
    hidden: true,
    children: [{
      path: 'template',
      name: 'Template',
      meta: {
        title: '导入模板'
      },
      component: () => import('@/page/importTemplate/index.vue')
    }]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRouterMap
})


export function resetRouter() {
  const newRouter = createRouter({
    history: createWebHistory(),
    routes: constantRouterMap
  })
  router.matcher = newRouter.matcher 
}


export default router
